const request = require('request')
const path = require('path');
const config = require('./config');
const analysis = require('./analysis');

var fs = require("fs")
function start(){
    request(config.url,function(err,res,body){
    
        if (!err && res){
            //console.log(body);
            analysis.findImg(body,downLoad);
        }
    })
}

function downLoad(imgUrl,i){
    let ext = imgUrl.split('.').pop();
    request(imgUrl).pipe(fs.createWriteStream(path.join(config.imgDir,i+'.'+ext),{
        'encoding':'utf8'
    },{autoClose:true}))
    console.log(i);
}

start();